import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;


public class InvokeSample {
	
	static final String SCRIPT = "function sayHello(names) { " 
								+         "for (i in names) {"
								+              "println('Hello ' + names[i] + '!');"
								+       "}"
								+"}";								

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ScriptEngine engine = new ScriptEngineManager().getEngineByName("js");
		try {
			engine.eval(SCRIPT);
			((Invocable)engine).invokeFunction("sayHello",
					(Object)new String []{"Minlwin","KgKg"});
		} catch (ScriptException e) {
			System.err.println("Script ဘာသာရပ်၏ ရေးသားပုံအမှားဖြစ်ပါသည်။");
		} catch (NoSuchMethodException e) {
			System.err.println("ခေါ်ယူလိုသော လုပ်ဆောင်ချက်ကို ရှာဖွေ၍ မရပါ။");
		}
	}

}
